package com.own.business.level.business.core;

import com.own.business.level.business.model.ExpModel;
import com.own.business.level.business.service.LevelUserService;
import com.own.component.common.login.user.BaseLoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * ExpRuleRun
 *
 * @author chenxueli
 * @date 2022-08-15 15:03:00
 */
@Slf4j
@Component
public class ExpRuleRun {

    @Resource
    private LevelUserService levelUserService;

    /**
     * 执行经验提升规则信息
     *
     * @param function  经验提升规则信息
     * @param loginUser 登录的用户信息
     */
    public void run(ExpRuleFunction function, BaseLoginUser loginUser) {
        var model = function.increase(loginUser.userId());
        if (model != ExpModel.ZERO && model.getExp() > 0) {
            // 找到用户信息，增加经验信息
            levelUserService.append(loginUser.userId(), model);
        }
    }

}
